
package com.timber.util;

import javax.swing.*;
import javax.swing.text.*;
import java.awt.event.*;


public class UpperCaseDocument extends PlainDocument
{
  public void insertString( int offs, String str, AttributeSet a )
    throws BadLocationException
  {
    if( str == null )
    {
      return;
    }

    char[] upper = str.toCharArray();
    int aChar;

    if( upper.length > 0 )
    {
      aChar = ( int )upper[ upper.length - 1 ];

      //  Some bogosity only on Sun keyboard - ENTER key tries to insert this
      //  after firing action performed - if we get this, just swallow it.
      if( aChar == 141 )
	return;
    }

    for( int i = 0; i < upper.length; i++ )
    {
      upper[ i ] = Character.toUpperCase( upper[ i ] );
    }

    super.insertString( offs, new String( upper ), a );
  }
}
